package com.tubeonfire.controller.admin;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tubeonfire.model.admin.FeedbackModel;

@SuppressWarnings("serial")
public class ListFeedbackServlet extends HttpServlet {

	private static final Logger log = Logger
			.getLogger(ListFeedbackServlet.class.getName());

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {
		try {
			int page = 1;
			try {
				page = Integer.parseInt((String) req.getParameter("page"));
			} catch (Exception e) {
				page = 1;
			}
			int status = 0;
			if (req.getParameter("status") != null
					&& req.getParameter("status").equals("1")) {
				status = 1;
			}
			FeedbackModel model = new FeedbackModel();
			model.setPage(page); 
			model.prepareList(status);			
			req.setAttribute("url", req.getRequestURL().toString());
			req.setAttribute("model", model);
			req.setAttribute("status", status);
			req.getRequestDispatcher("/admin/list_feedback.jsp").forward(req,
					resp);
		} catch (Exception e) {
			log.warning(e.toString());
			e.printStackTrace();
			resp.sendError(4004,
					"We are sorry for the inconvenience ! Please try again later !");
		}
	}
}
